package com.ybdz.scanner.utils;


import android.app.AlarmManager;
import android.app.Application;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Handler;

import com.tencent.bugly.crashreport.CrashReport;
import com.ybdz.scanner.activity.LoginActivity;
import com.ybdz.scanner.activity.WelcomeActivity;


/**
 * @ClassName: MyApplication
 * @author: zhao
 * @Description:
 * @date 2017/12/11 14:22
 */
public class MyApplication extends Application {

    private static Context context;
    private static Handler mMainThreadHandler;
    private static int mMainThreadId;
    private static String ScannerClick;

    public static String getScannerClick() {
        return ScannerClick;
    }

    public static void setScannerClick(String scannerClick) {
        ScannerClick = scannerClick;
    }

    public static Context getContext() {
        return context;
    }
    private PendingIntent intent;


    @Override
    public void onCreate() {
        super.onCreate();
        context=this;
        ScannerClick = null;
        //主线程的Handler
        mMainThreadHandler = new Handler();
        /**
         * 获取主线程的线程id
         * myTid:Thread
         * myPid:Process
         */
        mMainThreadId = android.os.Process.myTid();

        CrashReport.initCrashReport(getApplicationContext(), "bf72f4c719", false);

        //设置Thread Exception Handler
//        Thread.setDefaultUncaughtExceptionHandler(this);
//        intent = PendingIntent.getActivity(this, 0,new Intent(this, WelcomeActivity.class).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);


    }



    /**
     * 得到主线程里面的创建的一个hanlder
     */
    public static Handler getMainThreadHandler() {
        return mMainThreadHandler;
    }

    /**
     * 得到主线程的线程id
     */
    public static int getMainThreadId() {
        return mMainThreadId;
    }



//    @Override
//    public void uncaughtException(Thread t, Throwable e) {
//        AlarmManager mgr = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//        if (mgr != null){
//            mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 2000, intent);
//            android.os.Process.killProcess(android.os.Process.myPid()); //杀掉原进程防止黑屏
//        }
//
//    }

}
